package com.inspur.edp.bef.bemanager.validate.operation;

import com.inspur.edp.bef.bizentity.exceptions.BusinessEntityErrorCodeEnum;
import com.inspur.edp.bef.bizentity.exceptions.BusinessEntityException;
import com.inspur.edp.bef.bizentity.operation.BizActionBase;
import com.inspur.edp.bef.bizentity.operation.componentinterface.IBizParameter;
import org.codehaus.plexus.util.StringUtils;

import static com.inspur.edp.cef.designtime.api.validate.common.CheckUtil.isLegality;


public abstract class BizActionBaseChecker extends BizOperationChecker {
    //BE参数校验
    private void checkParameters(BizActionBase para) {
        for (Object par : para.getParameters()) {
            par = par instanceof IBizParameter ? (IBizParameter) par : null;
            if (par == null)
                return;
            if(StringUtils.isEmpty(((IBizParameter) par).getParamCode())){
                throw BusinessEntityException.createException(BusinessEntityErrorCodeEnum.GSP_BEMODEL_BUSINESS_ENTITY_0048,  para.getCode(), ((IBizParameter) par).getParamName());
            }
            if (isLegality(((IBizParameter) par).getParamCode()))
                continue;
            opException("方法[" + para.getCode() + "]的参数[" + ((IBizParameter) par).getParamCode() + "]是Java关键字，请修改！");
        }
    }

    protected final void checkBizActionBase(BizActionBase actionBase){
        checkBizOperation(actionBase);
        checkParameters(actionBase);
        checkBizActionExtented(actionBase);
    }

    protected void checkBizActionExtented(BizActionBase actionBase){
    }
}
